package com.example.mall.web.controller;

import com.example.mall.domain.InventoryLocks;
import com.example.mall.dto.InventoryLocksDto;
import com.example.mall.exception.ErrorEnumCode;
import com.example.mall.exception.GlobalCustomerException;
import com.example.mall.query.InventoryLocksQuery;
import com.example.mall.query.PageDTO;
import com.example.mall.result.JSONResult;
import com.example.mall.service.IInventoryLocksService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/inventoryLocks")
public class InventoryLocksController {

    @Autowired
    public IInventoryLocksService inventoryLocksService;

    /**
     * 分页查询库存锁定记录表信息
     * @param inventoryLocksQuery
     * @return
     */
    @GetMapping("queryPage")
    @ApiOperation(value = "分页查询库存锁定记录表信息",notes = "分页查询库存锁定记录表信息",httpMethod = "GET")
    public JSONResult queryPage(InventoryLocksQuery inventoryLocksQuery){
        PageDTO<InventoryLocksDto> inventoryLocksDtoPageDTO = inventoryLocksService.queryPage(inventoryLocksQuery);
        return JSONResult.success("查询成功",inventoryLocksDtoPageDTO);
    }

    /**
     * 根据id查询库存锁定记录表信息
     * @param lockId
     * @return
     */
    @GetMapping("query/{lockId}")
    @ApiOperation(value = "根据id查询库存锁定记录表信息",notes = "根据id查询库存锁定记录表信息",httpMethod = "GET")
    public JSONResult query(@PathVariable("lockId")Long lockId){
        //1.根据id查询用户信息
        if (lockId == null){
            throw new GlobalCustomerException(ErrorEnumCode.LOCKID_NOT_ID);
        }
        InventoryLocks inventoryLocks = inventoryLocksService.getById(lockId);
        return JSONResult.success("查询成功",inventoryLocks);
    }

    /**
     * 根据id查询库存锁定记录表信息
     * @param lockId
     * @return
     */
    @GetMapping("queryInventoryLocksById/{lockId}")
    @ApiOperation(value = "根据id查询库存锁定记录表信息",notes = "根据id查询库存锁定记录表信息",httpMethod = "GET")
    public JSONResult queryInventoryLocksById(@PathVariable("lockId")Long lockId){
        //1.根据id查询用户信息
        if (lockId == null){
            throw new GlobalCustomerException(ErrorEnumCode.LOCKID_NOT_ID);
        }
        InventoryLocks inventoryLocks = inventoryLocksService.queryInventoryLocksById(lockId);
        return JSONResult.success("查询成功",inventoryLocks);
    }

    /**
     * 查询全部库存锁定记录表信息
     * @param
     * @return
     */
    @GetMapping("queryInventoryLocksList")
    @ApiOperation(value = "查询全部库存锁定记录表信息",notes = "查询全部库存锁定记录表信息",httpMethod = "GET")
    public JSONResult queryInventoryLocksList(){
        List<InventoryLocks> inventoryLocks = inventoryLocksService.queryInventoryLocksList();
        return JSONResult.success("查询成功",inventoryLocks);
    }

    /**
     * 新增库存锁定记录表
     * @param inventoryLocksDto
     * @return
     */
    @PostMapping("insert")
    @ApiOperation(value = "新增库存锁定记录表",notes = "新增库存锁定记录表",httpMethod = "POST")
    public JSONResult insert(@RequestBody InventoryLocksDto inventoryLocksDto){
        inventoryLocksService.insert(inventoryLocksDto);
        return JSONResult.success("保存成功");
    }

    /**
     * 修改库存锁定记录表信息
     * @param inventoryLocksDto
     * @return
     */
    @PostMapping("update")
    @ApiOperation(value = "修改库存锁定记录表信息",notes = "修改库存锁定记录表信息",httpMethod = "POST")
    public JSONResult update(@RequestBody InventoryLocksDto inventoryLocksDto){
        inventoryLocksService.update(inventoryLocksDto);
        return JSONResult.success("修改成功");
    }

    /**
     * 删除库存锁定记录表信息
     * @param lockId
     * @return
     */
    @PostMapping("delete/{lockId}")
    @ApiOperation(value = "删除库存锁定记录表信息",notes = "删除库存锁定记录表信息",httpMethod = "POST")
    public JSONResult delete(@PathVariable("lockId") Long lockId) {
        inventoryLocksService.delete(lockId);
        return JSONResult.success("删除成功");
    }

    /**
     * 批量删除库存锁定记录表信息
     * @param lockIds
     * @return
     */
    @PostMapping("deleteBatch")
    @ApiOperation(value = "批量删除库存锁定记录表信息",notes = "批量删除库存锁定记录表信息",httpMethod = "POST")
    public JSONResult deleteAll(@RequestBody List<Long> lockIds) {
        inventoryLocksService.deleteBatch(lockIds);
        return JSONResult.success("批量删除成功");
    }
}
